declare module 'highlight.js'

export type IUserInputFormProps = {
  label: string
  variable: string
  required: boolean
  default: string
  options?: string[]
}

export enum IUserInputFormTypeEnums {
  textInput = 'text-input',
  paragraph = 'paragraph',
  select = 'select',
}

export type IUserInputForm = Record<IUserInputFormTypeEnums, IUserInputFormProps>

declare module 'axios' {
  export interface CustomResponse<T> {
    data?: T
    has_more?: boolean
    limit?: number
  }
  export interface AppInfoResponse {
    name: string
    description: string
    tags: string[]
  }
  export interface AppParametersResponse {
    opening_statement: string
    user_input_form: IUserInputForm[]
  }
}

export interface Conversation {
  id?: string
  key: string
  name: string
  introduction?: string
  status?: string
  created_at: number
  updated_at: number
  inputs: object
}

export enum ResponseMode {
  streaming = 'streaming',
  blocking = 'blocking',
}

export enum MessageFileType {
  document = 'document',
  image = 'image',
  audio = 'audio',
  video = 'video',
  custom = 'custom',
}

export enum MessageFileTransferMethod {
  remote_url = 'remote_url',
  local_file = 'local_file',
}

export interface MessageFile {
  type: MessageFileType
  transfer_method: MessageFileTransferMethod
  url?: string
  upload_file_id?: string
}

export interface SendMessageRequest {
  query: string
  inputs: object
  response_mode: ResponseMode
  user: string
  conversation_id?: string
  files: MessageFile[]
  auto_generate_name?: boolean
}

export enum RecordRole {
  user = 'user',
  assistant = 'assistant',
}

export interface RecordItem {
  id?: string
  role: RecordRole
  answer?: string
  query?: string
  conversation_id?: string
  error?: string
  status?: string
}

export enum TransferMethod {
  all = 'all',
  local_file = 'local_file',
  remote_url = 'remote_url',
}

export type VisionFile = {
  id?: string
  type: string
  transfer_method: TransferMethod
  url: string
  upload_file_id: string
  belongs_to?: string
}

export type ThoughtItem = {
  id: string
  tool: string // plugin or dataset. May has multi.
  thought: string
  tool_input: string
  message_id: string
  observation: string
  position: number
  files?: string[]
  message_files?: VisionFile[]
}

export type CitationItem = {
  content: string
  data_source_type: string
  dataset_name: string
  dataset_id: string
  document_id: string
  document_name: string
  hit_count: number
  index_node_hash: string
  segment_id: string
  segment_position: number
  score: number
  word_count: number
}

export type MessageEnd = {
  id: string
  metadata: {
    retriever_resources?: CitationItem[]
    annotation_reply: {
      id: string
      account: {
        id: string
        name: string
      }
    }
  }
}

export type MessageReplace = {
  id: string
  task_id: string
  answer: string
  conversation_id: string
}

export type AnnotationReply = {
  id: string
  task_id: string
  answer: string
  conversation_id: string
  annotation_id: string
  annotation_author_name: string
}

export type WorkflowStartedResponse = {
  task_id: string
  workflow_run_id: string
  event: string
  data: {
    id: string
    workflow_id: string
    sequence_number: number
    created_at: number
  }
}

export type WorkflowFinishedResponse = {
  task_id: string
  workflow_run_id: string
  event: string
  data: {
    id: string
    workflow_id: string
    status: string
    outputs: unknown
    error: string
    elapsed_time: number
    total_tokens: number
    total_steps: number
    created_at: number
    finished_at: number
  }
}

export type NodeStartedResponse = {
  task_id: string
  workflow_run_id: string
  event: string
  data: {
    id: string
    node_id: string
    node_type: string
    index: number
    predecessor_node_id?: string
    inputs: unknown
    created_at: number
    extras?: unknown
  }
}

export type NodeFinishedResponse = {
  task_id: string
  workflow_run_id: string
  event: string
  data: {
    id: string
    node_id: string
    node_type: string
    index: number
    predecessor_node_id?: string
    inputs: unknown
    process_data: unknown
    outputs: unknown
    status: string
    error: string
    elapsed_time: number
    execution_metadata: {
      total_tokens: number
      total_price: number
      currency: string
    }
    created_at: number
  }
}
